<template>
  <ChatWindow :chatInfo="chatInfo" />
</template>

<script>
import ChatWindow from './ChatWindow.vue';
import { useRoute } from 'vue-router';
import { computed } from 'vue';

export default {
  components: {
    ChatWindow,
  },
  setup() {
    const route = useRoute();
    const chatId = route.params.id;

    // 从 localStorage 中读取会话信息
    const conversations = JSON.parse(localStorage.getItem('conversations') || '[]');
    const chatInfo = computed(() => {
      return conversations.find((session) => session.id === parseInt(chatId, 10)) || {
        id: chatId,
        name: '未知会话',
        avatarColor: '#1890ff',
        type: 'personal',
      };
    });

    return { chatInfo };
  },
};
</script>